feat(M5c): the $eval builtin (parse+evaluate at runtime; wants_env hook)#16
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…group) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
M5c implements
$eval(expr [, context])— parse a string as a JSONata expression and evaluate it at runtime, faithfully to jsonata-js v2.2.1 (outer-scope variable visibility, D3120/D3121 error codes).wants_envhook —$evalis the first builtin that needs a live environment (to evaluate a newly-parsed AST so it can see builtins, outer-scope bound variables, and custom functions). Added an opt-in hook toM.apply: a builtin withwants_env = truereceives(env, input, ...args). The default dispatch path is byte-unchanged when the flag is absent.$eval(functions/eval.lua) — lazy-requires the parser + evaluator (breaks the load cycle);undefined → undefined;pcallparse → D3120; focus-or-current-input selection; evaluates against the caller's live env directly (so($x := 5; $eval('$x'))→ 5);pcallevaluate → D3121.pcallboundaries.Results
function-evalgroup is fully green.Verification
An adversarial fidelity review against a jsonata-js v2.2.1 oracle (~50 paired cases) confirmed error-code fidelity is exact (D3120/D3121 boundary + inner-error rewrap of
$assert/$errorinto D3121 all match — this is suite-invisible, as the suite runner checks only that an error was raised, not its code). It found two in-scope divergences, both fixed in465c605:'1+1' ~> $evalcrashed becauseenvwasn't threaded into the~>/partial-application apply paths (the "wire the hook into all apply paths" lesson from M5a) — now threaded.consflag and corrupted path indexing — now rebuilt clean.Deferred/logged (pre-existing, engine-wide, not
$eval-specific):$$root context broken;1/0→infvsnull; deep-nestedcons-array indexing; error-message text fidelity.Test Plan
bustedfull unit suite — 416/416scripts/run-suite.sh— 1147/1682, zero regressions🤖 Generated with Claude Code